
//发送get请求获取数据
$.getJSON('http://api.map.baidu.com/telematics/v3/weather?callback=?'
,{
	location: "郑州市",
	output: "json",
	ak: "iw5m2G7ayDow8ofDdDGVUMB3",
	mcode: "com.BaiduWeather"
}
,function(data){
	console.log(data);
	
	//取出天气结果result，在data.results也就这一个元素
	var result = data.results[0];
	
	//取出城市并显示
	$("header").text(result.currentCity);
	//取出pm25
	var pm25 = result.pm25;
	
	//获取当天的天气
	var today = result.weather_data[0];
	$("main .temper").text(today.temperature);
	$("main .weather").text(today.weather);
	$("main .wind").text(today.wind);
	$("main .icon").css("backgroundImage","url("+today.dayPictureUrl+")");
	var nowTemper = today.date.substr(today.date.indexOf("：")+1);
	nowTemper = nowTemper.replace(')','');
	$("main .current").text("实时温度"+nowTemper+",空气指数"+pm25+"，"+getPM25String(pm25));
	
	
	//获取并显示其他三天的天气
	var sections = $("section");
	for (var i = 1; i < result.weather_data.length; i ++) {
		//把天气拿出来，把section拿出来
		var section = sections[i-1];
		var weather = result.weather_data[i];
		//取值显示
		$(".week",section).text(weather.date);
		$(".icon",section).css("backgroundImage","url("+weather.dayPictureUrl+")");
		$(".temper",section).text(weather.temperature);
		$(".weather",section).text(weather.weather);
		$(".wind",section).text(weather.wind);
	}
});

//通过给定pm25设置，你给我返回一个对应的字符串
function getPM25String(pm){
	if (pm <= 50) {
		return "优";
	}else if (pm <= 100) {
		return "良";
	}else if (pm <= 200) {
		return "轻度污染";
	}else if (pm <= 300) {
		return "中度污染";
	}else if (pm <= 400) {
		return "重度污染";
	}else if (pm <= 500) {
		return "严重污染";
	}else{
		return "超级污染，来场大风吧，救救我们吧！";
	}
}

//封装一个方法，获取当前的城市
function getCurrentCity(){
	//……
	return "城市";
}
